package de.preisrobot.persistence.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import de.preisrobot.entity.Anbieter;

@Repository
public class AnbieterDaoImpl implements AnbieterDao
{
   @PersistenceContext
   private EntityManager em ;
   
   @Override
   @Transactional(propagation=Propagation.REQUIRED)
   public long save(Anbieter a){
      em.persist(a);
      return a.getId();
   }

   @Override
   public List<Anbieter> loadAll()
   {
      Query query = em.createQuery("select a from Anbieter a order by a.name");
      return query.getResultList();
   }
}
